<template>
  <div class='renew first-box'>
    <Tip></Tip>
    <Form :formData="formData" :formParam="formParam" ></Form>
    <Button class="margintop40" :buttonData="buttonData" ></Button>
  </div>
</template>
<script>
import Tip from '../../common/tip.vue'
import Form from '../../common/form'
import Button from '../../common/button.vue'
import {autoInsurance} from '../../../../static/data/selectdata.js'
export default {
  components: {Tip,Form,Button},
  name: "",
  data() {
    return {
      formData:[
        {
          title:{
            show:true,
            img:require("../../../assets/img/hpmepage/renew/detail.png"),
            label:"基本信息"
          },
          children:[
            {type:"input",label:"车型",key:"carType",checked:true},
            {type:"number",label:"落车价格",key:"carPrice",unit:"万元",checked:true},
            {type:"input",label:"车辆年限",key:"carAge",},
            {type:"select",label:"出险次数",key:"risksNum",array:new Array(50).fill("").map((val,index)=>index)},
            {type:"input",label:"姓名",key:"realName",readonly:true},
            {type:"select",label:"保险公司",key:"insuranceCompanyId",array:[]}
          ],
        },{
          title:{
            show:true,
            img:require("../../../assets/img/hpmepage/renew/type.png"),
            label:"选择险种"
          },
          children:[
            {type:"radio",label:"交强险",key:"strongInsurance",array:[{label:"6座以上",key:"0"},{label:"6座及以下",key:"1"}]},
            {type:"select",label:"第三方责任险",key:"thirdLiabilityInsurance",array:["50000","100000","200000","500000","1000000"],align:"right"},
            {type:"checkList",label:"",key:"thist",array:autoInsurance},
            {type:"select",label:"车身刮痕损失险",key:"carScratch",array:["2000","5000","10000","20000"],align:"right"},
            {type:"select",label:"司机座位责任险",key:"seatInsurance",array:["10000","50000"],align:"right"},
          ],
        },
      ],
      formParam:{
        strongInsurance:"1",
        thist:[],
        realName:"",
        carType:"",
        carPrice:"",
        carAge:"",
        risksNum:"",
        insuranceCompanyId:"",
        thirdLiabilityInsurance:"",
        carScratch:"",
        seatInsurance:"",
        employeeId:""
      },

      buttonData:[
        {
          label:"询价",
          click:this.consolte,
        },
        {
          label:"续保预约",
          click:this.save,
        }
      ]
    };
  },
  methods: {
    consolte(){
      var obj={
        userId:sessionStorage.getItem("userId")
      }
      for(var item of autoInsurance){
        obj[item.key]=0
      }
      for(var key in this.formParam){
        if(Array.isArray(this.formParam[key])){
          for(var item of this.formParam[key]){
            obj[item]=1
          }
        }else{
          obj[key]=this.formParam[key]
        }
      }

      if(_g.checkForm(this.formData,obj)==true){
        _g.apiPost("insurance/askPrice.do",obj).then(res=>{
          // if(res&&res.status==0){
          //   this.$store.state.dialogs.alert.content=res.msg
          //   this.$store.state.dialogs.alert.show=true
          // }
          _g.toMessage(res)
        })
      }
    },
    save(){
      this.$router.push("/appoints")
    },
    getList(){
      var params={
        userId:sessionStorage.getItem("userId")
      }
      _g.apiPost("insurance/init.do",params).then(res=>{
        this.formParam.realName=res.data.user.realName||""
        this.formParam.carType=res.data.vehicle.carModel||""
        this.formParam.carPrice=res.data.vehicle.carPrice||""

        var goal=[]
        res.data.comList.forEach(ele => {
          goal.push({
            key:ele.id,
            value:ele.name
          })
        });
        this.$set(this.formData[0].children[5],"array",goal)
        // this.formParam.realName=res.data.user.realName
        // this.formParam.realName=res.data.user.realName
      })
    }
  },
  created() {
    this.getList()
  }
};
</script>
<style lang="scss" scoped>
.renew {
  
}
.margintop40{
  padding: 40px 15px 40px;
}
</style>